/*
This is an example script for a 3D scatter graphic. Click the Execute button to apply and then execute this script. Upon each execution the 3D scatter alters its appearance. Turn on animation to execute periodically. Note that typically a 3D scatter graphic should be instantiated on a graph data layer and the graph should be set to autoscale during animation.
*/

/* Declarations */

double cos(double a);
double sin(double a);

@@class() PerspectiveScatter:Object

@@method(public, class) (id)stored;
@@method(public, instance) (void)emptyData;
@@method(public, instance) (unsigned)animationCount;
@@method(public, instance) (void)appendXValue:(double)xValue yValue:(double)yValue zValue:(double)zValue;
@@method(public, instance)(void)appendMarkerRed:(double)red green:(double)green blue:(double)blue alpha:(double)alpha;
@@method(public, instance) (void)setCurveRed:(double)red green:(double)green blue:(double)blue alpha:(double)alpha;
@@method(public, instance) (void)setInteriorRed:(double)red green:(double)green blue:(double)blue alpha:(double)alpha;
@@method(public, instance) (void) rotateToPhi:(double)phiAngle theta:(double)thetaAngle psi:(double)psiAngle;

@@end

/* Execution block */

{
id myScatter;
int ii;
double tValue, xValue, yValue, zValue;
unsigned animationCount;
double red;
double phiAngle;

myScatter = [PerspectiveScatter stored];

animationCount = [myScatter animationCount];

/*
Empty the data and then append new data.
*/

[myScatter emptyData];

for(ii = 0; ii < 500; ii++)
{
tValue = 0.04 * ii + animationCount * 0.5;
xValue = 5.0 * cos(tValue) + 5.0;
yValue = 5.0 * sin(tValue) + 5.0;
zValue = tValue / 2.0;
[myScatter appendXValue:xValue yValue:yValue zValue:zValue];

if(ii < 150)
{
[myScatter appendMarkerRed:1.0 green:0.0 blue:0.0 alpha:1.0];
}
else if(ii < 250)
{
[myScatter appendMarkerRed:1.0 green:0.0 blue:1.0 alpha:1.0];
}
else
{
[myScatter appendMarkerRed:0.0 green:0.0 blue:1.0 alpha:1.0];
}

}

red = (animationCount % 10) / 10.0;
phiAngle = animationCount * 0.1;

[myScatter setCurveRed:red green:0.0 blue:0.0 alpha:1.0];

[myScatter rotateToPhi:phiAngle theta:0.2 psi:0.0];

}

